﻿using Microsoft.Extensions.DependencyInjection;
using Modules.App.Repositories;
using PmSoft;

namespace Modules.App
{
    [UseDI(ServiceLifetime.Scoped)]
    public class AppDeviceService
    {
        private readonly AppDeviceRepository appDeviceRepository;

        public AppDeviceService(AppDeviceRepository appDeviceRepository)
        {
            this.appDeviceRepository = appDeviceRepository;
        }

        public AppDevice? GetAppDevice(int id)
        {
            return appDeviceRepository.Get(id);
        }

        /// <summary>
        /// 根据身份证号查询设备信息
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns></returns>
        public AppDevice? GetAppDeviceByIdCard(string idCard)
        {
            return appDeviceRepository.GetAppDeviceByIdCard(idCard);
        }

        /// <summary>
        /// 根据别名查询设备信息
        /// </summary>
        /// <param name="alias"></param>
        /// <returns></returns>
        public AppDevice? GetAppDeviceByAlias(string alias)
        {
            return appDeviceRepository.GetAppDeviceByAlias(alias);
        }

        public void Create(AppDevice device)
        {
            appDeviceRepository.Insert(device);
        }

        public void Update(AppDevice device)
        {
            appDeviceRepository.Update(device);
        }

        public IEnumerable<AppDevice> GetDevicesByProjectId(int projectId)
        {
            return appDeviceRepository.GetDevicesByProjectId(projectId);
        }
    }
}